/// @file utility.h @brief Contains a set of very useful and commonly used functions.
#pragma once
//#define __DEBUG__
#include <QPolygonF>
#include <list>
#include <QLinkedList>
#include <stdexcept>
#include <core/Tan.h>
#include <cmath>
#include <QMultiMap>
#include <iostream>
#include <QPointF>

namespace qtangram {
    /**
      @brief Determines whether two QPolygonF instances are connected to each other
      @return true if connected
      @param first first polygon
      @param second second polygon
    */
    bool connected(QPolygonF first, QPolygonF second);
    /**
      @brief Performs resizing on given polygon by given scale
      @param poly polygon to rescale
      @param sc  scale
      @return rescaled polygon's copy
    */
    QPolygonF scale(const QPolygonF& poly, double sc);
    /**
      @brief Performs resizing on given polygon by given scale in place
      @param poly polygon to rescale
      @param sc  scale
      @return rescaled polygon's copy
    */
    QPolygonF scaleInPlace(QPolygonF poly, double sc);
    /**
      @brief creates polygon that is sum of enlarged tans (polygons)
      @param tans List of Tans to be united
      @param margin outter margin in world's coordinates' system
      @throws std::runtime_error
      @return sum (union) of given tans
    */
    QPolygonF summEnlargedPolygons(const QLinkedList<Tan>& tans, double margin = 0) throw(std::runtime_error);
    /**
      @brief Enlarge polygon by adding outter margin
      @param poly polygon to be enlarged
      @param margin outter margin in world's coordinates' system
      @return enlarged polygon
    */
    QPolygonF enlargePolygon(const QPolygonF& poly, double margin);
    /**
      @brief Looks for polygon's geometric center coordinates
      @return point that is geometric center of provided polygon
    */
    QPointF geometricCenter(const QPolygonF& poly);
    double distance(const QPointF &, const QPointF &);
    Tan* findClosest(Tan & ref_tan, QLinkedList<Tan*> & tans);
}
